{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.103576Z",
     "start_time": "2025-01-13T08:52:24.699001Z"
    }
   },
   "source": "import numpy as np",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.107721Z",
     "start_time": "2025-01-13T08:52:25.104577Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24).reshape(4, 6).astype('float')\n",
    "t[1, 3:] = np.nan\n",
    "print(t)\n",
    "print('-------------------')\n",
    "print(t.shape)\n",
    "print(id(t))"
   ],
   "id": "cbd0ea08f3686ec2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8. nan nan nan]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21. 22. 23.]]\n",
      "-------------------\n",
      "(4, 6)\n",
      "3055753007856\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.113127Z",
     "start_time": "2025-01-13T08:52:25.108723Z"
    }
   },
   "cell_type": "code",
   "source": "t.shape[0]",
   "id": "a7fbb35f4cde43c7",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.117823Z",
     "start_time": "2025-01-13T08:52:25.114130Z"
    }
   },
   "cell_type": "code",
   "source": [
    "for i in range(t.shape[1]):\n",
    "    temp_col = t[:, i]\n",
    "    nan_num = np.count_nonzero(temp_col != temp_col)\n",
    "    if nan_num != 0:\n",
    "        temp_col_not_nan = temp_col[temp_col == temp_col]\n",
    "        print(temp_col_not_nan)\n",
    "        temp_col[np.isnan(temp_col)] = np.mean(temp_col_not_nan)\n",
    "print('-'*50)\n",
    "print(t)\n",
    "print(id(t))"
   ],
   "id": "522e65cd4431cfb7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 3. 15. 21.]\n",
      "[ 4. 16. 22.]\n",
      "[ 5. 17. 23.]\n",
      "--------------------------------------------------\n",
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8. 13. 14. 15.]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21. 22. 23.]]\n",
      "3055753007856\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.121829Z",
     "start_time": "2025-01-13T08:52:25.117823Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.arange(12).reshape(3, 4)\n",
    "print('原数组：')\n",
    "print(a)\n",
    "print('对换数组：')\n",
    "print(np.transpose(a))\n",
    "print('-'*50)\n",
    "print(a)\n",
    "print('-'*50)\n",
    "print(a.T)"
   ],
   "id": "f505806916e37127",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原数组：\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "对换数组：\n",
      "[[ 0  4  8]\n",
      " [ 1  5  9]\n",
      " [ 2  6 10]\n",
      " [ 3  7 11]]\n",
      "--------------------------------------------------\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "--------------------------------------------------\n",
      "[[ 0  4  8]\n",
      " [ 1  5  9]\n",
      " [ 2  6 10]\n",
      " [ 3  7 11]]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.125382Z",
     "start_time": "2025-01-13T08:52:25.121829Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t3 = np.arange(60).reshape(3, 4, 5)\n",
    "print(t3.shape)\n",
    "print('-' * 50)\n",
    "t3 = np.swapaxes(t3, 1, 2)\n",
    "print(t3.shape)"
   ],
   "id": "d6f2a93ad7b1fae5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 4, 5)\n",
      "--------------------------------------------------\n",
      "(3, 5, 4)\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:52:25.129399Z",
     "start_time": "2025-01-13T08:52:25.125382Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.ones((3, 4, 5, 6))\n",
    "b = np.rollaxis(a, 3, 1)\n",
    "print(b.shape)"
   ],
   "id": "47731b73acb7b9d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 6, 4, 5)\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:54:20.800836Z",
     "start_time": "2025-01-13T08:54:20.797454Z"
    }
   },
   "cell_type": "code",
   "source": [
    "c=np.rollaxis(b, 1,4) \n",
    "print(c.shape)"
   ],
   "id": "ac02f41af99e5f55",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 4, 5, 6)\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:57:42.655764Z",
     "start_time": "2025-01-13T08:57:42.652918Z"
    }
   },
   "cell_type": "code",
   "source": [
    "b = np.array([[1, 2, 3], [1, 2, 3]])\n",
    "a = b.copy()\n",
    "print(a)"
   ],
   "id": "65490ea24bed4742",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [1 2 3]]\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:57:44.896224Z",
     "start_time": "2025-01-13T08:57:44.893122Z"
    }
   },
   "cell_type": "code",
   "source": [
    "b[0, 0] = 3\n",
    "print(b)\n",
    "print(a)"
   ],
   "id": "dccee58d7ccaafba",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 2 3]\n",
      " [1 2 3]]\n",
      "[[1 2 3]\n",
      " [1 2 3]]\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T08:58:03.966395Z",
     "start_time": "2025-01-13T08:58:03.788418Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr = np.random.rand(2, 3, 4)\n",
    "print(arr)"
   ],
   "id": "ab5674c7bdd7e4eb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[0.09067144 0.80520346 0.77627171 0.2410104 ]\n",
      "  [0.32281117 0.89954428 0.96361998 0.38349704]\n",
      "  [0.47212399 0.44936182 0.42784413 0.95162235]]\n",
      "\n",
      " [[0.27507491 0.33061866 0.87084491 0.12752189]\n",
      "  [0.58511148 0.12196279 0.15159039 0.28711205]\n",
      "  [0.50569995 0.74412875 0.31950017 0.47168416]]]\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-13T09:15:59.655484Z",
     "start_time": "2025-01-13T09:15:59.651970Z"
    }
   },
   "cell_type": "code",
   "source": [
    "names = 'zhangsan,lisi,wangwu,zhaoliu,sunqi'\n",
    "with open('names.csv', 'w') as f:\n",
    "    f.write(names)\n",
    "    f.write('\\n')\n",
    "    f.write('12,23,34,45,56')"
   ],
   "id": "5566f7ab8af3d772",
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "ded4a3b3fd94fd56"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
